package se.zens.demo.wsapp.implementation.customers;

import java.util.Map;

import javax.ws.rs.core.Response;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import se.zens.demo.wsapp.configuration.WSAppConfiguration;
import se.zens.demo.wsapp.implementation.AbstractWSAppProcessor;
import se.zens.demo.wsapp.interfaces.model.Customer;

public class GetCustomerProcessor extends AbstractWSAppProcessor<Customer>
{ 
	private static Logger logger = LogManager.getLogger(GetCustomerProcessor.class);
	private Response response ;
	private Map<String, Customer> customers;
	private WSAppConfiguration config;
	private String id ;
	
	public GetCustomerProcessor(WSAppConfiguration config, String id,
			Map<String, Customer> customers)
	{
		this.config = config;
		this.id = id;
		this.customers = customers;
		this.config = config;
		
	}

	public GetCustomerProcessor(WSAppConfiguration config,
			Map<String, Customer> customers)
	{
		this.config = config;
		this.customers = customers;
		this.config = config;
	}

	@Override
	public void process()
	{
		if(id == null || id.trim().isEmpty() )
		{
			response = Response.noContent().build();
			return ;
		}
		
		if( customers == null || customers.isEmpty())
		{
			response = Response.noContent().build();
			return;
		}
		
		Customer cust = customers.get(id);
		if(cust == null)
		{
			response = Response.noContent().build();
			return;
		}	
		response = Response.ok(cust).build();
		
	}
	
	public Response getResponse()
	{
		return response;
	}

}
